home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / vsrc.tar / voyager7_src / list.c < prev    next >
C/C++ Source or Header  |  1991-02-27  |  3KB  |  171 lines

  1. /*
  2. // Abstract:
  3. //    LIST---List Comment
  4. //
  5. //    The List Comment module displays portions of the comment files.
  6. //
  7. // Author:
  8. //    Derek S. Nickel
  9. //
  10. // Creation date:
  11. //    23 January 1991
  12. //
  13. // History:
  14. // V01-001    Derek S. Nickel        23-JAN-1991
  15. //    Original.
  16. //
  17. */
  18.  
  19. #include <ctype.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <io.h>
  23.  
  24. #include "list.h"
  25. #include "index.h"
  26. #include "memory.h"
  27. #include "pager.h"
  28. #include "tree.h"
  29.  
  30. #define MAX_LINE 256
  31.  
  32. typedef struct _listdata_t listdata_t;
  33.  
  34. struct _listdata_t {
  35.     long matches;
  36.     bin5_t offset;
  37.     bin5_t start;
  38.     bin5_t end;
  39.     TextFile *tf;
  40.     char cbuf[MAX_LINE];
  41. };
  42.  
  43. static void search_port(int port_no, bin5_t start, bin5_t end,
  44. long *matches);
  45.  
  46. static int write_one_line(node_t *node, listdata_t *db);
  47.  
  48. /***********************************************************************
  49.     Messages.
  50. ***********************************************************************/
  51.  
  52. #define vgr__none \
  53. "%%VOYAGER-I-NONE, no comments found\n"
  54.  
  55. #define vgr__listed \
  56. "%%VOYAGER-I-LISTED, listed %ld comments\n"
  57.  
  58. /***********************************************************************
  59.     list_comment
  60. ***********************************************************************/
  61.  
  62. void list_comment(bin5_t start, bin5_t end)
  63. {
  64.     long matches = 0;
  65.  
  66.     /*
  67.     // Search each port in turn.
  68.     */
  69.  
  70.     if (ports[0].loaded) search_port(0, start, end, &matches);
  71.     if (ports[1].loaded) search_port(1, start, end, &matches);
  72.     if (ports[2].loaded) search_port(2, start, end, &matches);
  73.  
  74.     /*
  75.     // Print summary.
  76.     */
  77.  
  78.     pager(0);
  79.     if (matches == 0)
  80.         printf(vgr__none);
  81.     else
  82.         printf(vgr__listed, matches);
  83. }
  84.  
  85. /***********************************************************************
  86.     search_port
  87. ***********************************************************************/
  88.  
  89. static void search_port(int port_no, bin5_t start, bin5_t end,
  90. long *matches)
  91. {
  92.     bin5_t min_adr;
  93.     bin5_t max_adr;
  94.     listdata_t db;
  95.     cond_value sys_status;
  96.  
  97.     /*
  98.     // Define allowable search range for this port.
  99.     */
  100.  
  101.     min_adr = ports[port_no].min_adr;
  102.     max_adr = ports[port_no].max_adr;
  103.  
  104.     /*
  105.     // Verify correct sequencing.
  106.     */
  107.  
  108.     if (start > end) {
  109.         bin5_t tmp;
  110.         tmp = start;
  111.         start = end;
  112.         end = tmp;
  113.     }
  114.  
  115.     /*
  116.     // Search this port?
  117.     */
  118.  
  119.     if ((start < min_adr && end < min_adr) ||
  120.         (start > max_adr && end > max_adr))
  121.         return;
  122.  
  123.     /*
  124.     // Force start amd end into range.
  125.     */
  126.  
  127.     if (start < min_adr) start = min_adr;
  128.     if (end > max_adr) end = max_adr;
  129.  
  130.     /*
  131.     // Search for comment.
  132.     */
  133.  
  134.     db.matches = 0;
  135.     db.offset = min_adr;
  136.     db.start = start;
  137.     db.end = end;
  138.     db.tf = ports[port_no].ca_file;
  139.  
  140.     /*
  141.     // Search for comments.
  142.     */
  143.  
  144.     sys_status = traverse_tree(
  145.         &db.tf->root,
  146.         write_one_line,
  147.         &db );
  148.  
  149.     *matches += db.matches;
  150. }
  151.  
  152. static int write_one_line(node_t *node, listdata_t *db)
  153. {
  154.     char *cbufp = db->cbuf;
  155.     bin5_t adr = node->key + db->offset;
  156.  
  157.     if (db->start <= adr && adr <= db->end) {
  158.         if (!node->deleted) {
  159.             fseek(db->tf->f, node->value, SEEK_SET);
  160.             fgets(cbufp, MAX_LINE, db->tf->f);
  161.             db->cbuf[strlen(cbufp)-1] = '\0';
  162.             cbufp += 6;
  163.             db->matches++;
  164.             pager(0);
  165.             printf("%05lX %s\n", adr, cbufp);
  166.         }
  167.     }
  168.  
  169.     return 1;
  170. }
  171.